home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / lib / extra / setfiledate.c < prev    next >
C/C++ Source or Header  |  1997-09-09  |  2KB  |  92 lines

  1.  
  2.  
  3. /*
  4.  *  SETFILEDATE.C
  5.  *
  6.  *    (c)Copyright 1992-1997 Obvious Implementations Corp.  Redistribution and
  7.  *    use is allowed under the terms of the DICE-LICENSE FILE,
  8.  *    DICE-LICENSE.TXT.
  9.  *
  10.  *  BOOL = SetFileDate(filename, date)
  11.  *
  12.  *  Note, this call works under 1.3 and is equivalent to the 2.0
  13.  *  dos.library call.  We cannot enable dos pragmas here because they
  14.  *  will interfere with this routine's register conventions.
  15.  */
  16.  
  17. #include <exec/types.h>
  18. #include <exec/memory.h>
  19. #include <libraries/dos.h>
  20. #include <libraries/dosextens.h>
  21. #include <string.h>
  22. #include <clib/exec_protos.h>
  23. #undef __DICE_INLINE    /*  problem w/ inline SetFileDate() */
  24. #include <clib/dos_protos.h>
  25.  
  26. #define BTOC(bptr)  ((void *)((long)bptr << 2))
  27. #define CTOB(cptr)  ((BPTR)((long)cptr >> 2))
  28.  
  29. typedef void *Pointer;
  30.  
  31. #ifndef ACTION_SET_DATE
  32. #define ACTION_SET_DATE 34
  33. #endif
  34.  
  35. typedef struct StandardPacket STDPKT;
  36. typedef struct Process          PROC;
  37. typedef struct DateStamp      DATESTAMP;
  38. typedef struct FileLock       LOCK;
  39. typedef struct Message          MSG;
  40.  
  41. int
  42. SetFileDate(file, date)
  43. UBYTE *file;
  44. DATESTAMP *date;
  45. {
  46.     STDPKT *packet;
  47.     char   *buf;
  48.     PROC   *proc;
  49.     long   result;
  50.     BPTR   lock;
  51.     BPTR   flock = Lock(file, SHARED_LOCK);
  52.     short  i;
  53.     char *ptr = file;
  54.  
  55.     {
  56.     if (flock == NULL)
  57.         return(NULL);
  58.     lock = ParentDir(flock);
  59.     UnLock(flock);
  60.     if (!lock)
  61.         return(NULL);
  62.     for (i = strlen(ptr) - 1; i >= 0; --i) {
  63.         if (ptr[i] == '/' || ptr[i] == ':')
  64.         break;
  65.     }
  66.     file += i + 1;
  67.     }
  68.     proc   = (PROC *)FindTask(NULL);
  69.     packet = (STDPKT   *)AllocMem(sizeof(STDPKT), MEMF_CLEAR|MEMF_PUBLIC);
  70.     buf = AllocMem(strlen(file)+2, MEMF_PUBLIC);
  71.     strcpy(buf+1,file);
  72.     buf[0] = strlen(file);
  73.  
  74.     packet->sp_Msg.mn_Node.ln_Name = (char *)&(packet->sp_Pkt);
  75.     packet->sp_Pkt.dp_Link = &packet->sp_Msg;
  76.     packet->sp_Pkt.dp_Port = &proc->pr_MsgPort;
  77.     packet->sp_Pkt.dp_Type = ACTION_SET_DATE;
  78.     packet->sp_Pkt.dp_Arg1 = NULL;
  79.     packet->sp_Pkt.dp_Arg2 = (long)lock;        /*  lock on parent dir of file  */
  80.     packet->sp_Pkt.dp_Arg3 = (long)CTOB(buf);   /*  BPTR to BSTR of file name   */
  81.     packet->sp_Pkt.dp_Arg4 = (long)date;        /*  APTR to datestamp structure */
  82.     PutMsg(((LOCK *)BTOC(lock))->fl_Task, (MSG *)packet);
  83.     WaitPort(&proc->pr_MsgPort);
  84.     GetMsg(&proc->pr_MsgPort);
  85.     result = packet->sp_Pkt.dp_Res1;
  86.     FreeMem(packet, sizeof(STDPKT));
  87.     FreeMem(buf, strlen(file)+2);
  88.     UnLock(lock);
  89.     return(result);
  90. }
  91.  
  92.